<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta name="description" content="1. 首页1.1 分类查询 &#x2F;categorySearch?category1Id&#x3D;xxx&amp;category2Id&#x3D;xxx&amp;分页信息  controller: 调用SkuService的categorySearch(category1Id,category2Id,分页信息)  service:     先从缓存中查找  缓存的key:  缓存的value:  商品在缓存中的key">
<meta property="og:type" content="article">
<meta property="og:title" content="项目">
<meta property="og:url" content="http://yoursite.com/2020/05/22/%E9%A1%B9%E7%9B%AE/index.html">
<meta property="og:site_name" content="小蜗学习之旅">
<meta property="og:description" content="1. 首页1.1 分类查询 &#x2F;categorySearch?category1Id&#x3D;xxx&amp;category2Id&#x3D;xxx&amp;分页信息  controller: 调用SkuService的categorySearch(category1Id,category2Id,分页信息)  service:     先从缓存中查找  缓存的key:  缓存的value:  商品在缓存中的key">
<meta property="article:published_time" content="2020-05-22T14:16:26.000Z">
<meta property="article:modified_time" content="2020-05-23T07:58:28.828Z">
<meta property="article:author" content="小蜗">
<meta property="article:tag" content="JAVA基础">
<meta name="twitter:card" content="summary">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2020/05/22/项目/"/>





  <title>项目 | 小蜗学习之旅</title>
  








<meta name="generator" content="Hexo 4.2.1"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>	
	<a href="https://github.com/xiaoawo" target="_blank" rel="noopener" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
	<a href="https://github.com/xiaoawo" target="_blank" rel="noopener" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">小蜗学习之旅</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/home" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-schedule">
          <a href="/schedule/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-calendar"></i> <br />
            
            日程表
          </a>
        </li>
      
        
        <li class="menu-item menu-item-sitemap">
          <a href="/sitemap.xml" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-sitemap"></i> <br />
            
            站点地图
          </a>
        </li>
      
        
        <li class="menu-item menu-item-commonweal">
          <a href="/404/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-heartbeat"></i> <br />
            
            公益404
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/05/22/%E9%A1%B9%E7%9B%AE/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="小蜗">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/xiaoawo.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="小蜗学习之旅">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">项目</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-05-22T22:16:26+08:00">
                2020-05-22
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="1-首页"><a href="#1-首页" class="headerlink" title="1. 首页"></a>1. 首页</h2><h3 id="1-1-分类查询"><a href="#1-1-分类查询" class="headerlink" title="1.1 分类查询"></a>1.1 分类查询</h3><ol>
<li><p>/categorySearch?category1Id=xxx&amp;category2Id=xxx&amp;分页信息</p>
</li>
<li><p>controller: 调用SkuService的categorySearch(category1Id,category2Id,分页信息)</p>
</li>
<li><p>service:   </p>
<ul>
<li><p>先从缓存中查找<br>  缓存的key:<br>  缓存的value:  商品在缓存中的key<br>  使用的数据结构：list,LRU</p>
<p>  根据分页信息，计算出需要取的范围，然后从list中拿到对应的key,再根据这些key从缓存中拿到具体的数据，这个过程，如果缓存未命中，则直接跳过</p>
</li>
<li><p>缓存未命中再从数据库中查找<br>  根据传入的数据从数据库中查找，然后写入到缓存中</p>
</li>
</ul>
</li>
<li><p>返回查询结果</p>
</li>
</ol>
<h3 id="1-2-全文搜索"><a href="#1-2-全文搜索" class="headerlink" title="1.2 全文搜索"></a>1.2 全文搜索</h3><ol>
<li><p>/elasticSearch?category1Id=xxx&amp;category2Id=xxx&amp;分页信息&amp;关键字</p>
</li>
<li><p>controller: 调用searchService的search(category1Id,category2Id,分页信息,关键字)</p>
</li>
<li><p>service:<br> 构建DSL语句，执行并返回结果</p>
</li>
<li><p>返回查询结果</p>
</li>
</ol>
<h2 id="2-商品详情"><a href="#2-商品详情" class="headerlink" title="2. 商品详情"></a>2. 商品详情</h2><ol>
<li><p>/skuInfo?skuId=xxx</p>
</li>
<li><p>controller: 调用SkuService的skuInfo(skuId)</p>
</li>
<li><p>service:   </p>
<ul>
<li><p>先从缓存中查找<br>  缓存的key:<br>  缓存的value:  JSON(skuInfo)<br>  使用的数据结构：String</p>
</li>
<li><p>缓存未命中再从数据库中查找<br>  先加分布式锁  </p>
<pre><code>&amp;emsp;&amp;emsp;加锁成功：根据传入的数据从数据库中查找，然后写入到缓存中（写入的数据中，包含一个标识，代表该数据是否有效，即是否从数据库中查询到了正确数据）  
&amp;emsp;&amp;emsp;加锁失败：自旋一段时间后再从缓存中读</code></pre></li>
</ul>
</li>
<li><p>返回查询结果</p>
</li>
</ol>
<h2 id="3-购物车"><a href="#3-购物车" class="headerlink" title="3. 购物车"></a>3. 购物车</h2><ol>
<li>从商品详情中点击加入购物车，会跳到购物车   /add2Cart?skuId=xxx //加入到购物车<br>在主页点击我的购物车，也会跳到购物车      /listCart //展示购物车  </li>
</ol>
<pre><code>调用之前会先经过拦截器，判断是否登录成功</code></pre><ol start="2">
<li><p>controller: 调用CartService的add2Cart(skuId)   listCart()</p>
</li>
<li><p>service:   </p>
<ul>
<li><p>add2Cart(skuId)：直接写入到数据库中即可【不确定，也有可能直接和缓存交互，退出购物车时，再刷新到数据库中】</p>
<p>listCart()：【看下谷粒中怎么做的，为什么用hash结构】</p>
</li>
<li><p>先从缓存中查找<br>  缓存的key:<br>  缓存的value:  JSON(skuInfo)<br>  使用的数据结构：String</p>
</li>
<li><p>缓存未命中再从数据库中查找<br>  先加分布式锁  </p>
<pre><code>&amp;emsp;&amp;emsp;加锁成功：根据传入的数据从数据库中查找，然后写入到缓存中（写入的数据中，包含一个标识，代表该数据是否有效，即是否从数据库中查询到了正确数据）  
&amp;emsp;&amp;emsp;加锁失败：自旋一段时间后再从缓存中读</code></pre></li>
</ul>
</li>
<li><p>返回查询结果</p>
</li>
</ol>
<h2 id="4-订单"><a href="#4-订单" class="headerlink" title="4. 订单"></a>4. 订单</h2><ol>
<li>在购物车页面，点击去结算，会跳到结算页<br>/listOrder //展示所有订单</li>
</ol>
<pre><code>调用之前会先经过拦截器，判断是否登录成功</code></pre><ol start="2">
<li><p>controller: 调用OrderService的结算()   listOrder()</p>
</li>
<li><p>service:   </p>
<ul>
<li><p>结算：<br>listCart()：【看下谷粒中怎么做的，为什么用hash结构】</p>
</li>
<li><p>先从缓存中查找<br>  缓存的key:<br>  缓存的value:  JSON(skuInfo)<br>  使用的数据结构：String</p>
</li>
<li><p>缓存未命中再从数据库中查找<br>  先加分布式锁  </p>
<pre><code>&amp;emsp;&amp;emsp;加锁成功：根据传入的数据从数据库中查找，然后写入到缓存中（写入的数据中，包含一个标识，代表该数据是否有效，即是否从数据库中查询到了正确数据）  
&amp;emsp;&amp;emsp;加锁失败：自旋一段时间后再从缓存中读</code></pre></li>
</ul>
</li>
<li><p>返回查询结果</p>
</li>
</ol>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2020/05/22/MySQL-%E4%BA%8B%E5%8A%A1/" rel="next" title="MySQL-事务">
                <i class="fa fa-chevron-left"></i> MySQL-事务
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2020/05/23/Linux/" rel="prev" title="Linux">
                Linux <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/xiaoawo.jpg"
                alt="小蜗" />
            
              <p class="site-author-name" itemprop="name">小蜗</p>
              <p class="site-description motion-element" itemprop="description">凡心所向，素履所往，生如逆旅，一苇以航</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/%7C%7C%20archive">
              
                  <span class="site-state-item-count">25</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">9</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-首页"><span class="nav-number">1.</span> <span class="nav-text">1. 首页</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-1-分类查询"><span class="nav-number">1.1.</span> <span class="nav-text">1.1 分类查询</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-2-全文搜索"><span class="nav-number">1.2.</span> <span class="nav-text">1.2 全文搜索</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-商品详情"><span class="nav-number">2.</span> <span class="nav-text">2. 商品详情</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-购物车"><span class="nav-number">3.</span> <span class="nav-text">3. 购物车</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-订单"><span class="nav-number">4.</span> <span class="nav-text">4. 订单</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">小蜗</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  



  
  









  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  

  
  
    <script type="text/javascript" src="/lib/three/three.min.js"></script>
  

  
  
    <script type="text/javascript" src="/lib/three/three-waves.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
